package com.ctshk.rpc.airexpress.mapper;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.ctshk.rpc.airexpress.entity.AirportExpressIncreaseStrategy;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 产品加幅策略表 Mapper 接口
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-02-05
 */
public class AirportExpressIncreaseStrategyProvider {
    public String selectIdListByAirportExpressIds(List<Long> airportExpressIds) {
        return new SQL() {{
            SELECT("select aeis.id ");
            FROM("t_airport_express_increase_strategy aeis");
            if (CollectionUtils.isNotEmpty(airportExpressIds)) {
                StringBuilder whereStr = new StringBuilder();
                whereStr.append("aeis.airport_express_id in (");
                for (int i = 0; i < airportExpressIds.size(); i++) {
                    whereStr.append("#{list.get(0)}");
                    if (i == airportExpressIds.size() - 1) {
                        whereStr.append(")");
                    } else {
                        whereStr.append(",");
                    }
                }
                WHERE(whereStr.toString());
            }
        }}.toString();
    }

    public String selectByAirportExpressIdNowDate(@Param("airportExpressId") Long airportExpressId, @Param("nowDate") String nowDate) {
        return new SQL() {{
            SELECT("aeis.id, aeis.increase_strategy_name, aeis.self_sale_permission_type, aeis.agent_sale_permission_type, aeis.airport_express_id, aeis.self_sale_permission_id, aeis.agent_sale_permission_id ");
            FROM("t_airport_express_increase_strategy aeis ");
            LEFT_OUTER_JOIN("t_airport_express_increase_strategy_date aeisd ON (aeis.id=aeisd.increase_strategy_id)");
            WHERE("aeis.airport_express_id = #{airportExpressId}");
            WHERE("#{nowDate} between aeisd.date_begin AND aeisd.date_end");
        }}.toString();
    }
}
